package general.servlet.util;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @desc 描述
 * create on 2018/10/25 by watson
 */
public class IOUtils {

    /**
     * 获取 HttpServletRequest 中的 BufferedReader 的所有字符
     * @param request
     * @return
     * @throws IOException
     */
    public static String getString(HttpServletRequest request) throws IOException {
        return getString(request.getReader());
    }

    /**
     * 获取 BufferedReader 中的所有字符
     * @param reader
     * @return
     * @throws IOException
     */
    public static String getString(BufferedReader reader) throws IOException {
        StringBuffer stringBuffer = new StringBuffer();
        String line = null;
        while ((line = reader.readLine()) != null) {
            stringBuffer.append(line);
        }
        reader.close();
        return stringBuffer.toString();
    }

}
